package com.company.链表;

import java.util.Scanner;

/**
 * @author zhangjian
 * @data 2023/2/19
 * @Version 1.0
 */
public class AB9链表 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();

        NodeImpl nodeImpl = new NodeImpl();
        String str = "";

        for (int i = 0; i <= n; i++) {
            String line = input.nextLine();
            if (line.contains("insert")) {
                String[] strSplit = line.split(" ");
                int x = Integer.parseInt(strSplit[1].trim());
                int y = Integer.parseInt(strSplit[2].trim());
                Node node = new Node(y);
                nodeImpl.addNode(node, x);
            } else if (line.contains("delete")) {
                int x = Integer.parseInt(line.split(" ")[1].trim());
                nodeImpl.deleteNode(x);
            }
        }
        str = nodeImpl.showNode();
        System.out.println(str.substring(1, str.length() - 1).trim());

    }
}

class Node {
    public int data;
    public Node next;

    public Node(int data) {
        this.data = data;
    }

    public Node() {
    }

    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }
}

class NodeImpl {
    private Node head = new Node();

    public void addNode(Node node, int x) {
        Node temp = head;
        while (true) {
            if (temp.next != null) {
                if (temp.next.data == x) {
                    node.next = temp.next;
                    temp.next = node;
                    break;
                } else {
                    temp = temp.next;
                }
            } else {
                temp.next = node;
                break;
            }
        }
    }

    public void deleteNode(int x) {
        Node temp = head;
        if (temp.next != null) {
            while (true) {
                if (temp.next.data == x) {
                    temp.next = temp.next.next;
                    break;
                } else {
                    temp = temp.next;
                }
            }
        } else {
            System.out.println("NULL");
        }
    }

    public String showNode() {
        Node temp = head;
        StringBuilder sb = new StringBuilder();
        if (temp.next != null) {
            while (true) {
                if (temp.next != null) {
                    sb.append(temp.data).append(" ");
                    temp = temp.next;
                } else {
                    sb.append(temp.data).append(" ");
                    break;
                }
            }
        } else {
            return "  NULL ";
        }
        return sb.toString();
    }
}